import Vue from 'vue';
import Router from 'vue-router';
//定懒加载方式的路由
const Login   = resolve => require(['@/components/auth/login.vue'], resolve);
const Base    = resolve => require(['@/components/layout/base.vue'], resolve);
//主页
const Main    = resolve => require(['@/components/index/index.vue'], resolve);
//管理员
const Manage  = resolve => require(['@/components/manage/index.vue'], resolve);
//角色
const Role    = resolve => require(['@/components/role/index.vue'], resolve);
const Access  = resolve => require(['@/components/role/access.vue'], resolve);
//文章
const Article  = resolve => require(['@/components/article/index.vue'], resolve);
const ArticleUpdate = resolve => require(['@/components/article/update.vue'], resolve);
//分类
const Category  = resolve => require(['@/components/category/index.vue'], resolve);
//背景
const Back  = resolve => require(['@/components/back/index.vue'], resolve);
//模板消息
const Message  = resolve => require(['@/components/message/index.vue'], resolve);
//推送记录
const Record  = resolve => require(['@/components/message/record.vue'], resolve);
//配置项
const Config  = resolve => require(['@/components/config/index.vue'], resolve);
//用户
const User  = resolve => require(['@/components/user/index.vue'], resolve);
//404
const Error404= resolve => require(['@/components/page/404.vue'], resolve);
Vue.use(Router);
//设置不需要权限的公共页面
//login 登录成功后不能在访问该页面
export const constantRouterMap= [
    {path: '/', name: 'Login', component: Login, meta: {title: '登录', login:true}},
    {
        path: '/',
        component: Base,
        children:[
            {
                path: '/main',
                name: 'Main',
                meta: {title:'美文首页',show:true,'icon':'fa fa-home'},
                component: Main,
            },
            {
                path: '/error/404',
                meta: {title:'404',show:false},
                component: Error404,
            },
        ],
    }
];
//实例化vue的时候只挂载constantRouter
export default new Router({
    mode: 'history',
    routes: constantRouterMap
});
//异步挂载的路由
//动态需要根据权限加载的路由表
//access：权限ID，show：菜单是否展示，title:页面title,icon:菜单图标
export const asyncRouterMap = [
    {
        path: '/',
        component: Base,
        children:[
            {
                path: '/article',
                name: 'Article',
                meta: {title:'文章管理',show:true,'icon':'fa fa-file-text'},
                component: Article,
            },
            {
                path: '/article/update/:id?',
                name: 'ArticleUpdate',
                meta: {title:'文章管理',show:false},
                component: ArticleUpdate,
            },
            {
                path: '/config',
                name: 'Config',
                meta: {title:'配置管理',show:true,'icon':'fa fa-wrench'},
                component: Config,
            },
            {
                path: '/category',
                name: 'Category',
                meta: {title:'分类管理',show:true,'icon':'fa fa-list'},
                component: Category,
            },
            {
                path: '/back',
                name: 'Back',
                meta: {title:'背景管理',show:true,'icon':'fa fa-file-picture-o'},
                component: Back,
            },
            {
                path: '/message',
                name: 'Message',
                meta: {title:'模板消息',show:true,'icon':'fa fa-comments'},
                component: Message,
            },
            {
                path: '/record',
                name: 'Record',
                meta: {title:'推送记录',show:true,'icon':'fa fa-feed'},
                component: Record,
            },
            {
                path: '/manage',
                name: 'Manage',
                meta: {title:'管理员',show:true,'icon':'fa fa-gavel'},
                component: Manage,
            },
            {
                path: '/user',
                name: 'User',
                meta: {title:'用户管理',show:true,'icon':'fa fa-user-o'},
                component: User,
            },
            {
                path: '/role',
                name: 'Role',
                meta: {title:'角色管理',show:true,'icon':'fa fa-flag'},
                component: Role,
            },
            {
                path: '/role/access/:id',
                name: 'Access',
                meta: {title:'权限管理',show:false},
                component: Access,
            },

        ]
    },
    { path: '*',name:'404', redirect: '/error/404',meta: {show:false}, }
];
